//处理需要字符串分割值的属性
exports.attrValueSplit = function (val,list) {
  let valList = String(val).split(' ')
   let j
  for (let i = 0; i < list.length; i++) {
        j = i
    if (j > valList.length-1) {
          j= valList.length -1
        }
     list[i](valList[j])
  }
}

 
// let pixelRatio = 1
// export let toPx = (rpx, int = false, factor = 1) => {
//   if (int) {
//     return Math.ceil(rpx * factor * pixelRatio);
//   }
//   return rpx * factor * pixelRatio;
// }
/**
 * @description px => rpx
 * @param { number } px - 需要转换的数值
 * @param { boolean} int - 是否为 int
 * @param { number } factor - 转化因子
 * @returns { number }
 */
// export let toRpx = (px , int  = false, factor = 1) => {
//   if (int) {
//     return Math.ceil(px / factor);
//   }
//   return px / factor;
// }

exports._drawRadiusRect = function ({data, options}) {
  const { x, y, w, h, r } = data;
  const {
    ctx,
  } = options;
  const br = r / 2;
  ctx.beginPath();
  ctx.moveTo(x + br, y);    // 移动到左上角的点
  ctx.lineTo(x + w - br, y);
  ctx.arc(x + w - br, y + br, br, 2 * Math.PI * (3 / 4), 2 * Math.PI * (4 / 4))
  ctx.lineTo(x + w, y + h - br);
  ctx.arc(x + w - br, y + h - br, br, 0, 2 * Math.PI * (1 / 4))
  ctx.lineTo(x + br, y + h);
  ctx.arc(x + br, y + h - br, br, 2 * Math.PI * (1 / 4), 2 * Math.PI * (2 / 4))
  ctx.lineTo(x, y + br);
  ctx.arc(x + br, y + br, br, 2 * Math.PI * (2 / 4), 2 * Math.PI * (3 / 4))
}

/**
获取最大高度
 */
exports.getHeight =    (config) => {
  const getTextHeight = (text) => {
    let fontHeight = text.lineHeight || text.fontSize;
    let height = 0;
    if (text.baseLine === 'top') {
      height = fontHeight;
    } else if (text.baseLine === 'middle') {
      height = fontHeight / 2;
    } else {
      height = 0;
    }
    return height;
  }
  const heightArr  = [];
  (config.blocks || []).forEach((item) => {
    heightArr.push(item.y + item.height);
  });
  (config.texts || []).forEach((item) => {
    let height;
    height = getTextHeight(item);
    heightArr.push(item.y + height);
  });
  (config.images || []).forEach((item) => {
    heightArr.push(item.y + item.height);
  });
  (config.lines || []).forEach((item) => {
    heightArr.push(item.startY);
    heightArr.push(item.endY);
  });
  const sortRes = heightArr.sort((a, b) => b - a);
  let canvasHeight = 0;
  if (sortRes.length > 0) {
    canvasHeight = sortRes[0];
  }
  console.log('canvasHeight',canvasHeight);
  if (config.height < canvasHeight || !config.height) {
    return canvasHeight;
  } else {
    return config.height;
  }
}